<!--
 * @Author: HeAo
 * @Date: 2021-10-09 11:13:26
 * @LastEditTime: 2021-10-15 10:32:44
 * @LastEditors: HeAo
 * @Description: 
 * @FilePath: \web2103-2105\web2105\3-2-Vue\day02\5-监听器.html
 * 别乱动！
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="app">
    {{user}}
    <input type="text" v-model.lazy="user.username">
    <select v-model="user.gender">
      <option value="male">男</option>
      <option value="female">女</option>
    </select>
    <button @click="user = {}">按钮</button>
  </div>
  <script>
    let vm = new Vue({
      el: '#app',
      data: {
        user: {
          username: null,
          gender: null
        }
      },
      watch: {
        // username(newValue, oldValue) {
        //   console.log(newValue, oldValue);
        //   queryUser()
        // }
        // user(newValue, oldValue) {
        //   console.log(newValue, oldValue);
        // }
        user: {
          handler(newValue, oldValue) {
            console.log('new', newValue);
            console.log('old', oldValue);
          },
          deep: true
        }
      },
      methods: {
        queryUser() {
          axios.get('/user/query', {
            username: this.username
          })
        }
      },
      created() {

      }
    })
  </script>
</body>

</html>